<!DOCTYPE html>
<html>
<head>
    <title>打印</title>
    <meta charset="utf-8">
    <style>
        .printBox {
            width: 300px;
            height: 300px;
            border: 1px solid blue;
        }
    </style>
    <!-- 打印的样式-->
    <style media="print">
        @page {
            size: 100px 75px;
            margin: 0mm;
        }
    </style>
    <script src="/jquery-3.6.0.min.js"></script>
    <script src="/dist_JsBarcode.all.min.js"></script>
</head>

<body>
<!--<div class="printBox">-->

<!--</div>-->
<!--startprint-->
<div style="text-align: center;width: 200px;height:75px;font-size: 9px">
    <div id="htime">
        2022-02-02 11:11:11
    </div>
    <svg id="svgcode"></svg>
    <!-- or -->
    <!--    <canvas id="canvascode"></canvas>-->
    <!--    &lt;!&ndash; or &ndash;&gt;-->
    <!--        <img id="imgcode"/>-->
    <div><span id="hproject"></span> <span id="hcount" style="margin-left: 5px"></span>个</div>
</div>
<!--endprint-->
<script>
    // var that = this
    // var date = new Date()
    // var seperator1 = '-'
    // var seperator2 = ':'
    // var month = date.getMonth() + 1
    // var strDate = date.getDate()
    // if (month >= 1 && month <= 9) {
    //     month = '0' + month
    // }
    // if (strDate >= 0 && strDate <= 9) {
    //     strDate = '0' + strDate
    // }
    // var hours = date.getHours()
    // if (hours >= 0 && hours <= 9) {
    //     hours = '0' + hours
    // }
    // var minutes = date.getMinutes()
    // if (minutes >= 0 && minutes <= 9) {
    //     minutes = '0' + minutes
    // }
    // var seconds = date.getSeconds()
    // if (seconds >= 0 && seconds <= 9) {
    //     seconds = '0' + seconds
    // }
    // var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
    //     ' ' + hours + seperator2 + minutes +
    //     seperator2 + seconds
    // localStorage.setItem("kkhtime",currentdate);
    var hcode = localStorage.getItem("kkhcode");
    var hproject = localStorage.getItem("hproject");
    var kkhtime = localStorage.getItem("kkhtime");
    var hcount = localStorage.getItem("hcount");
    $("#htime").html(kkhtime)
    $("#hcount").html(hcount)
    $("#hproject").html(hproject)
    $("#svgcode").JsBarcode(hcode, {width: 1.3, height: 50});
    // $("#canvascode").JsBarcode("22222");
    // $("#imgcode").JsBarcode("19599738913993500",{width:1.3});
</script>

<!--<div style="margin-top: 200px;">-->
<!--&lt;!&ndash;    <button onclick='print_page()'>打印</button>&ndash;&gt;-->
<!--</div>-->
</body>

<script type="text/javascript">
    function print_page() {
        if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie
            remove_ie_header_and_footer();
        }
        bdhtml = window.document.body.innerHTML;
        var oldstr = document.body.innerHTML;
        sprnstr = "<!--startprint-->";
        eprnstr = "<!--endprint-->";
        prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML = prnhtml;
        console.log(prnhtml);
        window.print();
        document.body.innerHTML = oldstr;

    }

    function remove_ie_header_and_footer() {
        var hkey_path;
        hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
        try {
            var RegWsh = new ActiveXObject("WScript.Shell");
            RegWsh.RegWrite(hkey_path + "header", "");
            RegWsh.RegWrite(hkey_path + "footer", "");
        } catch (e) {
        }
    }

    print_page()
</script>
</html>
